package servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Miss Chen
 * @version 1.0
 * @date 2024年09月02日13:53
 */

@WebServlet("/method")
public class MethodServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String contextPath=request.getContextPath();
        System.out.println("应用名:"+contextPath);


        //一般情况下，是浏览器地址应用名后面的命令，表示的是url-pattern
        String servletPath=request.getServletPath();
        System.out.println("servletPath:"+servletPath);


        //浏览器地址栏端口号后面的所有地址
        String uri=request.getRequestURI();
        System.out.println("uri:"+uri);

        //浏览器完整地址
        StringBuffer url=request.getRequestURL();
        System.out.println("url:"+url);

        //获取访问者的ip地址
        String ip=request.getRemoteAddr();
        System.out.println("ip:"+ip);
    }
}
